<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../../js/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/footer.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/gift_sell.css" />
		<style type="text/css">
			#content {
				/*padding-top: 0.763888rem;*/
				padding-top: 0.8rem;
			}
			
			a#fahuo {
				position: fixed;
				/*top: ;*/
				bottom: 1rem;
				z-index: 2;
			}
			
			a#jishou {
				position: fixed;
				/*top: ;*/
				bottom: 1rem;
				z-index: 2;
			}
			
			a.del {
				position: relative;
				z-index: 20;
			}
			
			.duihuan_box {
				display: none;
				width: 100%;
				height: 100%;
				position: absolute;
				top: 0;
				left: 0;
				background-color: rgba(0, 0, 0, 0.3);
			}
			
			.duihuan {
				width: 6.944444rem;
				height: 4.152777rem;
				background-color: white;
				margin: 0 auto;
				margin-top: 5rem;
				position: absolute;
				left: 50%;
				margin-left: -3.49rem;
			}
			
			.duihuan_top {
				font-size: 0.416666rem;
				color: #E8323E;
				text-align: center;
				padding-top: 0.888888rem;
				padding-bottom: 1.444444rem;
			}
			
			.duihuan_down {
				width: 5.902777rem;
				height: 1.388888rem;
				margin: 0 auto;
				border-top: 1px solid #DBDBDB;
			}
			
			.duihuan_down a {
				width: 2.013888rem;
				height: 0.694444rem;
				border: 1px solid #E8323E;
				margin-top: 0.208333rem;
				text-align: center;
				line-height: 0.694444rem;
				border-radius: 0.694444rem;
			}
			
			.duihuan_down a:nth-child(1) {
				float: left;
				color: white;
				background-color: #E8323E;
			}
			
			.duihuan_down a:nth-child(2) {
				float: right;
				color: #E8323E;
			}
			/*寄卖弹框*/
			
			.duihuan_box1 {
				display: none;
				width: 100%;
				height: 100%;
				position: absolute;
				top: 0;
				left: 0;
				background-color: rgba(0, 0, 0, 0.3);
			}
			
			.duihuan1 {
				width: 6.944444rem;
				height: 4.152777rem;
				background-color: white;
				margin: 0 auto;
				margin-top: 5rem;
				position: absolute;
				left: 50%;
				margin-left: -3.49rem;
			}
			
			.duihuan_top1 {
				font-size: 0.416666rem;
				color: #E8323E;
				text-align: center;
				padding-top: 0.888888rem;
				padding-bottom: 1.444444rem;
			}
			
			.duihuan_down1 {
				width: 5.902777rem;
				height: 1.388888rem;
				margin: 0 auto;
				border-top: 1px solid #DBDBDB;
			}
			
			.duihuan_down1 a {
				width: 2.013888rem;
				height: 0.694444rem;
				border: 1px solid #E8323E;
				margin-top: 0.208333rem;
				text-align: center;
				line-height: 0.694444rem;
				border-radius: 0.694444rem;
			}
			
			.duihuan_down1 a:nth-child(1) {
				float: left;
				color: white;
				background-color: #E8323E;
			}
			
			.duihuan_down1 a:nth-child(2) {
				float: right;
				color: #E8323E;
			}
			.duihuanImg{
				position: absolute;
				right: 0.2rem;
				top: 0.2rem;
			}
			.duihuanImg img{
				width: 2.0833rem;
			}
			div.gift_sell_wap ul li{
				margin-top: 0.7rem;
			}
		</style>
		<script src="../../../js/flexible.min.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body style="overflow: auto;">
		<div id="wrap">
			<div id="main">
				<div id="header">
					<a id="headImg" href="javascript:history.go(-1)"><img class="headImg" src="../../../images/12.png" /></a>
					<p id="headTitle">商品购物车</p>
				</div>
				<div id="content" style="overflow: auto;">
					<div class="gift_sell_wap" style="overflow: auto;">
						<ul style="overflow: auto; height: auto;">
							<!--<li>
								<div class="gift_left foods_detail_pic">
									<img src="../../../images/coalltion/mianbao.jpg"/>
								</div>
								<div class="gift_right">
									<p id="shopName">红牛</p>
									<p id="shopPrice">积分:35</p>
									<p></p>
									
								</div>
								<div class="duihuan">
									<img src="../../../images/store/duihuan.png"/>
								</div>
							</li>-->
						</ul>
					</div>
					<a style="left: 5.6rem;width: 3rem;" id="fahuo">发货</a>
					<a style="left: 9rem; width: 3rem;" id="jishou">寄售</a>
				</div>
			</div>
		</div>
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
				</button>
						<h4 class="modal-title" id="myModalLabel">
					编辑收货地址
				</h4>

					</div>
					<div class="modal-body">
						<input type="text" class="form-control" name="" id="addName" style="margin-bottom: 0.2rem;" placeholder="请输入联系人姓名" value="" />
						<input type="text" class="form-control" name="" id="phone" style="margin-bottom: 0.2rem;" placeholder="请输入联系人电话" value="" />
						<input type="text" class="form-control" name="" id="address" style="margin-bottom: 0.2rem;" placeholder="请输入详细地址" value="" />

					</div>
					<div class="modal-footer">
						<button type="button" id="fahuoQuxiao" class="btn btn-default" data-dismiss="modal">关闭
				</button>
						<button type="button" id="fahuoTrue" class="btn btn-danger">
					确定
				</button>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>
			<!-- /.modal-dialog -->
		</div>
		<!-- /.modal -->
		<div class="duihuan_box">
			<div class="duihuan">
				<div class="duihuan_top">
					确定发货吗？
				</div>
				<div class="duihuan_down">
					<a id="queding" style="cursor: pointer;" data-toggle="modal" data-target="#myModal">确定</a>
					<a href="#">取消</a>
				</div>
			</div>
		</div>
		<div class="duihuan_box1">
			<div class="duihuan1">
				<div class="duihuan_top1">
					确定寄卖吗？
				</div>
				<div class="duihuan_down1">
					<a id="queding1">确定</a>
					<a href="#">取消</a>
				</div>
			</div>
		</div>
	</body>
	<script src="../../../js/jquery-2.2.3.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		function UrlSearch() {
			var name, value;
			var str = location.href; //取得整个地址栏
			var num = str.indexOf("?")
			str = str.substr(num + 1); //取得所有参数   stringvar.substr(start [, length ]

			var arr = str.split("&"); //各个参数放到数组里
			for(var i = 0; i < arr.length; i++) {
				num = arr[i].indexOf("=");
				if(num > 0) {
					name = arr[i].substring(0, num);
					value = arr[i].substr(num + 1);
					this[name] = value;
				}
			}
		}
		var add = '';
		var Request = new UrlSearch();
		var orderSn = Request.orderSn;
		//获取会员信息
		$.ajax({
			type: "get",
			url: "http://47.104.13.109/member-service/auth/current?token=" + $.cookie("tokenRh"),
			async: true,
			success: function(res) {
				console.log(res)
				var goodsName;
				$.ajax({
					type: "get",
					url: "http://47.104.13.109:80/cart-service/selectorder?orderSn="+orderSn,
					async: true,
					success: function(data) {
						console.log(data)
						$.each(data, function(idx, item) {
							console.log(data.length)
						
								goodsName = item.goodsName
								var lis = '<li>' +
									'<div class="gift_left foods_detail_pic">' +
									'<img src="' + item.goodsPic + '"/>' +
									'</div>' +
									'<div class="gift_right">' +
									'<p id="shopName">' + item.goodsName + '</p>' +
									'<p id="shopPrice">积分:' + item.goodsIntegral + '&nbsp;&nbsp;数量' + item.goodsCount + '</p>' +
									'<p><input type="hidden" name="check" id="check"  value="' + item.cartId + '"/>&nbsp;&nbsp;&nbsp;&nbsp; ' +
									//									'<button class="del">删除</button></p>'+
									'</div>' +
									'<div class="duihuanImg">' +
									'<img src="../../../images/store/duihuan.png"/>' +
									'</div>' +
									'</li>'

								$(".gift_sell_wap ul").append(lis);
							
						});

					}
				});

			}
		});
		$("#queding1").on('click', function() {
			$("#queding1").attr('disabled', true)
			//获取会员信息
			$.ajax({
				type: "get",
				url: "http://47.104.13.109/member-service/auth/current?token=" + $.cookie("tokenRh"),
				async: true,
				success: function(res) {
					if($('#check').val() != '') {
						var cartId = $('#check').val();
						//判断是否是会员
						//				alert(res.roleList["0"].id)
						//				if(true){
						var check = false;
						for(var i = 0; i < res.roleList.length; i++) {
							if(res.roleList[i].id == 'f1' || res.roleList[i].id == 'f2') {
								check = true;
							}
						}
						if(check) {
							//					alert(cartId)
							// 转卖商品调id  积分购物车转卖接口（/updatestatus）
							$.ajax({
								type: "post",
								url: "http://47.104.13.109/cart-service/updatestatus?Cartid=" + cartId,
								async: true,
								success: function(res1) {
									//						console.log(res1)
									// 通过cartID查询数据
									$.ajax({
										type: "get",
										url: "http://47.104.13.109/order-service/selectbyid?orderSn=" + orderSn,
										async: true,
										success: function(res2) {
											console.log(res2)
											//生成转卖订单 转卖订单生成接口 （/updateresell）
											$.ajax({
												type: "post",
												url: "http://47.104.13.109/order-service/updateresell?orderId=" + res2.orderId,
												async: true,
												success: function(res3) {
													console.log(res3)
													$.ajax({
														type: "put",
														url: "http://47.104.13.109/information-service/information/send",
														async: true,
														data: {
															inforSendperson: '系统管理员',
															inforContent: '您在礼享商城兑换的商品' + $("#shopName").html() + '已经申请转卖啦!!!祝你购物愉快~~',
															inforReceiveperson: $.cookie("memberId"),
														},
														success: function(res5) {
															alert("您的商品已经寄卖成功")
															window.location.href = '../store.html';
															$("#queding1").attr('disabled', false)
															return false;
														},
														error: function(error) {
															alert("出现错误，请联系管理员");
															$("#queding1").attr('disabled', false)
														}

													});

												},
												error: function(error) {
													$("#queding1").attr('disabled', false)
												}
											});
										}
									});

								}
							});

						} else {
							window.location.href = 'git_sell_stu.html';

						}
					}
				},
				error: function(error) {
					$("#jishou").attr('disabled', false)
				}
			})
		})
		$("#fahuoQuxiao").on('click', function() {
			$("#fahuoTrue").bind("click");
		})
		$("#fahuoTrue").on("click", function() {
			//正则验证
			var zhengzphoone = /^1[3|4|5|7|8][0-9]{9}$/;
			if($("#addName").val() == '') {
				return alert("请输入联系人姓名");
			}
			if($("#phone").val() == '') {
				return alert("请输入联系电话");
			}
			if(!zhengzphoone.test($("#phone").val())) {
				return alert("请输入正确的手机号码")
			}
			if($("#address").val() == '') {
				return alert("请输入收货地址");
			}
			name = $("#addName").val();
			add = $("#address").val();
			phone = $("#phone").val();
			$("#fahuoTrue").unbind("click") //点击事件失效
			$.ajax({
				type: "get",
				url: "http://47.104.13.109/member-service/auth/current?token=" + $.cookie("tokenRh"),
				async: true,
				success: function(res) {
					console.log(res)
					//发货
					var cartId = $('#check').val();
					console.log(cartId)
					//通过订单编号查询订单id
					$.ajax({
						type: "get",
						url: "http://47.104.13.109/order-service/selectbyid?orderSn=" + orderSn,
						async: true,
						success: function(res2) {
							console.log(res2);
							if(!res2) {
								alert("订单数据查询错误")
								return
							}
							$.ajax({
								type:"get",
								url:"http://47.104.13.109:80/cart-service/selectorder",
								async:true,
								data:{
									orderSn : orderSn
								},
								success:function(resC){
									console.log(resC["0"].cartId)
							//礼享商城购物车领取借口（/hqupdate）
							$.ajax({
								type: "post",
								url: "http://47.104.13.109:80/cart-service/hqupdate?CartId=" + resC["0"].cartId,
								async: true,
								success: function(res4) {
//									console.log(res4)
									//修改订单状态
									console.log(res2.orderId)
									$.ajax({
										type: "post",
										url: "http://47.104.13.109:80/order-service/updateorder",
										async: true,
										data: {
											orderId: res2.orderId,
											userName: $("#addName").val(),
											userPhone: $("#phone").val(),
											userAddress: $("#address").val(),
										},
										success: function(res3) {
											console.log(res3)
											$.ajax({
												type: "put",
												url: "http://47.104.13.109/information-service/information/send",
												async: true,
												data: {
													inforSendperson: '系统管理员',
													inforContent: '您在礼享商城兑换商品' + $("#shopName").html() + '已经申请发货啦!!!祝你购物愉快~~',
													inforReceiveperson: $.cookie("memberId"),
												},
												success: function(res3) {
													alert("您的订单已经接收 稍后给您发货");
													console.log(res3)
													window.location.href = '../store_gift/store_gift.html';

													return false;
												},
												error: function(res4) {
													alert("出现错误，请联系管理员");
													$("#fahuoTrue").attr('disabled', false)
												}

											});

										},
										error: function(error) {
											alert("出现错误，请联系管理员");
											$("#fahuoTrue").attr('disabled', false)
										}
									});
								},
								error: function(error) {
									alert("出现错误，请联系管理员");
									$("#fahuoTrue").attr('disabled', false)
								}
							});
							},
								error:function(error){
									alert("查询购物车id时发生错误")
								}
							});
						},
						error: function(error) {
							console.log("出现错误，请联系管理员");
							$("#fahuoTrue").attr('disabled', false)
						}
					});
				},
				error: function(error) {
					$("#fahuoTrue").attr('disabled', false)
				}
			});
		})
		//发货弹框
		$('#fahuo').on('touchend', function() {
			$('.duihuan_box').css("display", "block");

		});
		$('.duihuan_down a:first').on('touchend', function() {

		});
		$('.duihuan_down a:last').on('touchend', function() {
			$('.duihuan_box').css("display", "none");
		});
		//寄卖弹框
		$('#jishou').on('touchend', function() {
			$('.duihuan_box1').css("display", "block");

		});
		$('.duihuan_down1 a:first').on('touchend', function() {

		});
		$('.duihuan_down1 a:last').on('touchend', function() {
			$('.duihuan_box1').css("display", "none");
		});
		
	
		
		
		
	</script>

</html>